import requests

from common.db_tools import DBTools
from common.get_header_tools import get_header


class IhrmManage:
    def add_emp(self,req_header,req_body):
        # 添加员工
        req_header=get_header()

        resp = requests.post(url="http://ihrm2-test.itheima.net/api/sys/user",
                             headers=req_header,json=req_body)
                             # json={
                             #     "username": "user87655430",
                             #     "mobile": "13947884780",
                             #     "workNumber": "9527890aa"
                             # })
        return resp
    def get_emp(self,emp_id,req_header):


        # 查询员工
        resp = requests.get(url="http://ihrm2-test.itheima.net/api/sys/user/"+emp_id,
                            headers=req_header)
        return resp
    def revise_emp(self,emp_id,req_header,req_body):
        # 修改员工
        resp = requests.put(url="http://ihrm2-test.itheima.net/api/sys/user/"+emp_id,
                            headers=req_header,json=req_body)
        return resp
    def delete_emp(self,emp_id,req_header):
        # 删除员工
        resp = requests.delete(url="http://ihrm2-test.itheima.net/api/sys/user/"+emp_id,
                               headers=req_header)
        DBTools.db_idu("delete from bs_user where mobile  ='13947884596';")
        return resp
if __name__ == '__main__':
    ihrm=IhrmManage()
    req_header = get_header()
    req_body={"username": "user87655430",
              "mobile": "13947884596",
            "workNumber": "9527890aa"}
    res1=ihrm.add_emp(req_header,req_body)
    print("添加员工：",res1.json())
    # result=res.json()
    # print(result)
    # print(result.get("data").get("id"))
    emp_id=res1.json().get("data").get("id")
    res2=ihrm.get_emp(emp_id,req_header)
    print("查询员工：",res2)

    req_body={"username":"多多小可爱99"}
    res3=ihrm.revise_emp(emp_id,req_header,req_body)
    print("修改员工：",res3.json())

    res4=ihrm.delete_emp(emp_id,req_header)
    print("删除员工:",res4.json())
    # DBTools.db_idu("delete from bs_user where mobile  ='13947884596';")